[^.] causing headache in RewriteRule

Posted by Ollie2893 on Stack Overflow See other posts from Stack Overflow or by Ollie2893
Published on 2010-03-08T16:48:13Z Indexed on 2010/03/08 16:51 UTC
Read the original article Hit count: 169

Filed under:
|
|

I am struggling with a very basic regex problem in my .htaccess file that I hope someone may be able to shed some light on. The basic premise is that I would like to teach Apache to switch any .html extension into a .var extension. I had thought that the rule would be positively trivial:

RewriteRule ^([^.]+)\.html$ $1.var

But the [^.] part simply doesn't work. Bizarrely, it works like so

RewriteRule ^([^A-Z]+)\.html$ $1.var

I do not understand why this latter rule works. Assume I am looking for a file called "index.html" then $1 should match to "index." and the ".html" bit should actually fail to match.

To widen the scope of the question slightly, I am actually racking my brain on how to implement a multi-lingual site. I don't like Apache's MultiView option because it forces upon me a flat directory structure with file extensions that aren't recognizable to many development tools. I could go the .var type-map route but am finding that the default config for Apache doesn't support this all that well either (hence my excursions into regex land). So while I am using mod_rewrite, I am thinking that I might go the whole hog: whenever a request for a name.html file is received and this file does not exist, check whether there exists a XX/name.html file instead, where "XX" is the language code according to the user's preferences.

This would give me a neater directory structure, though it does perhaps not perform as well as the .var approach in a situation where the language preference of the user's browser is not supported in by my site (in which situation .var would substitute EN or similar).

Any thoughts? Thanks.

© Stack Overflow or respective owner

Related posts about .htaccess

Related posts about apache